Skip to content

Comments

Bluetooth: stabilize BT_SCAN_PAIR and centralize controller helpers#217

Merged
vnarapar merged 2 commits intoqualcomm-linux:mainfrom
smuppand:bt-scan-fix
Nov 28, 2025
Merged

Bluetooth: stabilize BT_SCAN_PAIR and centralize controller helpers#217
vnarapar merged 2 commits intoqualcomm-linux:mainfrom
smuppand:bt-scan-fix

Conversation

@smuppand
Copy link
Contributor

What this PR brings

  • Wire BT_SCAN_PAIR to reuse lib_bluetooth.sh helpers (adapter detect, public-addr, power).
  • Support LAVA-exported BT_MAC plus CLI arg, with fallback to bt_device_list.txt.
  • Keep all BT logs in the test directory instead of /tmp.
  • Harden controller visibility, rfkill / HCI bring-up, and post-pair connect + l2ping checks for consistent CI results.

- Add rfkill/sysfs based helpers (rfkillunblocksysfs, listhcis, findhcisysfs)
  and btgetbdaddr() to reliably discover HCI adapters and their BD_ADDR.
- Make bt_l2ping_check() more tolerant by adding a short grace period after
  connect, retrying l2ping a couple of times, and logging each attempt, which
  avoids false FAILs when manual l2ping is already stable.

Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
- Source lib_bluetooth.sh alongside functestlib to reuse common BT helpers.
- Dynamically detect the Bluetooth adapter (BT_ADAPTER) via listhcis instead of
  hard-coding hci0.
- Resolve effective BT_MAC from (in order): environment, CLI argument, and
  bt_device_list.txt fallback, keeping BT_MAC as the common variable name for
  LAVA secrets.
- Ensure the controller is visible to bluetoothctl using
  bt_ensure_controller_visible(), which applies public-addr when needed.
- Use btpower() to power on the adapter only when required, rather than always
  forcing hciconfig up.
- Remove all previously paired devices before starting the test, and perform
  per-MAC cleanup via bt_cleanup_paired_device() in the trap.
- Implement direct pairing path for BT_MAC with PAIR_RETRIES, calling
  bt_pair_with_mac(), bt_post_pair_connect(), and bt_l2ping_check() and writing
  BT_SCAN_PAIR.res as PASS/FAIL while always exiting with status 0 for LAVA.

Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
# Output: prints "MAC NAME" lines; returns 0 if any device (or MAC_ID) found.
# shellcheck disable=SC2120
bt_scan_devices() {
bt_scan_devices_expect() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see this function being used anywhere. is this required?
Logic is similar to the new function bt_scan_devices, can u please check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see this function being used anywhere. is this required? Logic is similar to the new function bt_scan_devices, can u please check?

Yes, these functions are kept for future use in case logic based on expect is required. There are no plans to remove them.


# Pair with Bluetooth device using MAC (with retries and timestamped logs)
bt_pair_with_mac() {
bt_pair_with_mac_expect() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Here as well


# Post-pairing connection test with bluetoothctl and l2ping fallback
bt_post_pair_connect() {
bt_post_pair_connect_1() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Here as well

@smuppand smuppand requested a review from vnarapar November 25, 2025 04:55
Copy link
Contributor

@vnarapar vnarapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vnarapar vnarapar merged commit 7602dd7 into qualcomm-linux:main Nov 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants